//
//  SYTopView.swift
//  SingWeibo
//
//  Created by shiying on 15/12/20.
//  Copyright © 2015年 shiying. All rights reserved.
//

import UIKit

import SDWebImage

class SYStatusTopView: UIView {
    
    var status: SYStatus? {
        didSet{
            
            /// 设置头像
            if let profile_image_url = status?.user?.profile_image_url {
                let url = NSURL(string: profile_image_url)!
                iconView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "avatar"))
            }
            
            nameLable.text = status?.user?.screen_name
            
            timeLable.text = NSDate.timeDateToDate(status!.created_at!).timeDateDesription()
            
            ipLabel.text = status?.source
        
            vipView.image = status?.user?.mbrankImage
            
            verifiedView.image = status?.user?.verifiedImage
           
        }
    }
 
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        prepareUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func prepareUI() {
        self.addSubview(separatorView)
        self.addSubview(iconView)
        self.addSubview(nameLable)
        self.addSubview(vipView)
        self.addSubview(timeLable)
        self.addSubview(ipLabel)
        self.addSubview(verifiedView)
        
        
        separatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: CGFloat(UIScreen.mainScreen().bounds.size.width), height: 10))
        // 头像
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: separatorView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        
        // 名称
        nameLable.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        
        // 时间
        timeLable.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        
        // 来源
        ipLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLable, size: nil, offset: CGPoint(x: 8, y: 0))
        
        // 会员等级
        vipView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLable, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 8, y: 0))
        
        // 认证图标
        verifiedView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))
        
    
    }
    
    
    
    //Mark: - 懒加载
    
    /// 分割线
    lazy var separatorView: UIView = {
    
        let view = UIView()
        view.backgroundColor = UIColor(white: 0.95, alpha: 1)
        return view
    }()
    
    /// 头像
    lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar"))
    
    /// 昵称
    lazy var nameLable: UILabel = {
        let label = UILabel()
        
        label.font = UIFont.systemFontOfSize(13)
        label.textColor = UIColor.blackColor()
    
        return label
    }()
    
    /// vip
    lazy var vipView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_expired"))
 
    
    /// 时间
    lazy var timeLable: UILabel = {
        let label = UILabel()
        
        label.textColor = UIColor.orangeColor()
        label.font = UIFont.systemFontOfSize(10)
        
        return label
    }()
    
    /// ipLable
    lazy var ipLabel: UILabel = {
        let label = UILabel()
        
        label.font = UIFont.systemFontOfSize(10)
        label.textColor = UIColor.grayColor()
        label.sizeToFit()
        
        return label
    }()
    
    /// 认证图标
    lazy var verifiedView: UIImageView = UIImageView(image: nil)
}
